<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core">

    <ui:composition template="layout.xhtml">
        <ui:define name="body">
            <h:form id="itbiForm" enctype="multipart/form-data">
                <p:growl id="messages"  autoUpdate="true"  />
                <p:panel id="principalPanel" style="background: none; border: none;" 
                         styleClass="container_24 clearfix ">

                    <p:tabView id="itbiTabView">
                        <p:tab title="Configurações do Cálculo do ITBI">

                            <p:panel id="dadosPanel" style="background: none; border: none;" 
                                     styleClass="container_24 clearfix">
                                <h4 class="title">Alíquota</h4>
                                <p:outputLabel value="Financiado por Inst. Financeiras (%)" styleClass="grid_7" for="aliquotaFinan"/>
                                <p:inputText id="aliquotaFinan" styleClass="grid_4" value="#{managerConfigItbi.configItbi.aliquotaInstFinan}" required="true" />
                                <p:outputLabel  for="aliquota" value="Demais Transações (%)" styleClass="grid_5" />
                                <p:inputText id="aliquota" styleClass="grid_4" value="#{managerConfigItbi.configItbi.aliquota}" required="true" />
                            </p:panel>
                            <p:panel id="grupobairropanel" style="background: none; border: none;" 
                                     styleClass="container_24 clearfix ">
                                
                                <h4 class="title">Valor m² por Bairro</h4>
                                <p:outputLabel value="Descrição" styleClass="grid_3" for="descricaoInputText" />
                                <p:inputText id="descricaoInputText" styleClass="grid_8" required="true" 
                                             value="#{managerConfigItbi.grupoBairro.descricao}" />
                                <p:outputLabel value="Valor" styleClass="grid_3" for="vm2VttInputText" />
                                <p:inputText id="vm2VttInputText" styleClass="grid_4" required="true" 
                                             value="#{managerConfigItbi.grupoBairro.vm2}" />
                                <p:pickList 
                                    id="grupoBairropickList"
                                    value="#{managerConfigItbi.dualBairros}"
                                    var="bairro"
                                    converter="bairroconverter"
                                    itemLabel="#{bairro.nome}"
                                    itemValue="#{bairro}" 
                                    showSourceFilter="true"
                                    showTargetFilter="true"
                                    filterMatchMode="contains">
                                    <f:facet name="sourceCaption">Disponíveis</f:facet>  
                                    <f:facet name="targetCaption">Selecionados</f:facet>  
                                </p:pickList>

                                <div class="buttonAction">
                                    <p:commandButton value="Adicionar"
                                                     process=":itbiForm:itbiTabView:vm2VttInputText, :itbiForm:itbiTabView:descricaoInputText, :itbiForm:itbiTabView:grupoBairropickList, :itbiForm:itbiTabView:grupobairrodataTable, @this"
                                                     update=":itbiForm:itbiTabView:vm2VttInputText, :itbiForm:itbiTabView:descricaoInputText, :itbiForm:itbiTabView:grupoBairropickList, :itbiForm:itbiTabView:grupobairrodataTable"
                                                     actionListener="#{managerConfigItbi.addGrupoBairro()}"
                                                     id="addOnwerCommandButton" icon="ui-icon-plus"/>
                                </div>  
                                <br />
                                <p:dataTable var="grupobairro" value="#{managerConfigItbi.configItbi.gruposBairros}" id="grupobairrodataTable"
                                             rows="5" paginator="true"  
                                             paginatorPosition="bottom" emptyMessage="Nenhum registro">

                                    <p:column headerText="Ação" width="60">
                                        <p:commandButton title="Editar"
                                                         icon="ui-icon-pencil"
                                                         process=":itbiForm:itbiTabView:grupobairrodataTable"
                                                         update=":itbiForm:itbiTabView:vm2VttInputText, :itbiForm:itbiTabView:descricaoInputText, :itbiForm:itbiTabView:grupoBairropickList, :itbiForm:itbiTabView:grupobairrodataTable"
                                                         actionListener="#{managerConfigItbi.editarGrupoBairro(grupobairro)}"/>
                                        <p:commandButton title="Remover"
                                                 update=":itbiForm:itbiTabView:grupoBairropickList, :itbiForm:itbiTabView:grupobairrodataTable"
                                                 process=":itbiForm:itbiTabView:grupobairrodataTable"
                                                 actionListener="#{managerConfigItbi.removerGrupoBairro(grupobairro)}"
                                                 icon="ui-icon-trash"/>
                                    </p:column>
                                    <p:column headerText="Vm²">
                                        <h:outputText value="#{grupobairro.vm2}" />
                                    </p:column>
                                    <p:column headerText="Descrição">
                                        <h:outputText value="#{grupobairro.descricao}" />
                                    </p:column>
                                </p:dataTable>
                            </p:panel>

                            <div class="buttonAction">
                                <p:commandButton value="Salvar" icon="ui-icon-disk"
                                                 update="@form"
                                                 process="@this, aliquotaFinan, aliquota"
                                                 actionListener="#{managerConfigItbi.salvar()}"
                                                 styleClass="ui-priority-primary" />

                                <p:button href="index.xhtml" value="Cancelar"  icon="ui-icon-trash" />
                            </div>

                        </p:tab>
                    </p:tabView>
                </p:panel>

            </h:form>
        </ui:define>
    </ui:composition>
</html>